﻿using Project.DAL.information;
using Project.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project.BLL.information
{
    public class user_infoBll : BaseBLL<user_info>
    {
        public override void SetDal()
        {
            Dal=new user_infoDal(); 
        }
        //分页查询
        public List<user_info> GetUser_Infos(int page,int size,string name, out int count)
        {
            var list = base.Query();
            if(!string.IsNullOrEmpty(name) )
            {
                list=list.Where(x=>x.username.Contains(name));
            }
            count=list.Count();
            var data=list.OrderBy(u=>u.user_id).Skip((page-1)*size).Take(size);
            return data.ToList();
        }
        //删除
        public bool Del(int id)
        {
            var data= base.Query().Where(x=>x.user_id==id).FirstOrDefault();
            if(data!=null)
            {
                Dal.Delete  (data);
                return Dal.SaveChanges();
            }
            else
            {
                return false;   
            }
        }

        //批量删除
        public bool Del(int[] ids)
        {
            var data = base .Query().Where(x=>ids.Contains(x.user_id)).ToList();
            if(data!=null)
            {
                Dal.Delete(data);
                return Dal.SaveChanges();
            }
            else
            {
                return false;
            }
        }
    }
}
